package org.example.springbootdeptemp.service.impl;

import org.example.springbootdeptemp.mapper.DeptMapper;
import org.example.springbootdeptemp.mapper.EmpMapper;
import org.example.springbootdeptemp.pojo.Dept;
import org.example.springbootdeptemp.pojo.Emp;
import org.example.springbootdeptemp.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;
    @Autowired
    private EmpMapper empMapper;

    @Override
    public int updateDepts(Dept dept) {
        return deptMapper.updateDepts(dept);
    }

    @Override
    public int deleteDepts(Integer id) {
        return deptMapper.deleteDepts(id);
    }

    @Override
    public Dept selectById(Integer id) {
        return deptMapper.selectById(id);
    }

    @Override
    public int insertDept(Dept dept) {
        return deptMapper.insert(dept);
    }

    @Override
    public List<Dept> selectAll() {
        return deptMapper.selectAll();
    }

    @Override
    public Dept selectByEmp(Integer id) {
        List<Emp> emps = empMapper.selectByDeptId(id);
        Dept dept = deptMapper.selectById(id);
        dept.setEmps(emps);
        return dept;
    }
}
